package com.example.park2301.news

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.get
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingData
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.lib_base.entity.NewsBeanItem
import com.example.park2301.R
import com.example.park2301.databinding.ItemNewsBinding

class NewsAdapter:PagingDataAdapter<NewsBeanItem, NewsAdapter.NewsViewHolder>(holl) {
    companion object{
        val holl = object :ItemCallback<NewsBeanItem>(){
            override fun areItemsTheSame(oldItem: NewsBeanItem, newItem: NewsBeanItem): Boolean {
                return oldItem==newItem
            }

            override fun areContentsTheSame(oldItem: NewsBeanItem, newItem: NewsBeanItem): Boolean {
                return oldItem.id==newItem.id
            }

        }
    }
    class NewsViewHolder(view:View):ViewHolder(view){
        val binding =DataBindingUtil.bind<ItemNewsBinding>(view)
    }

    override fun onBindViewHolder(holder: NewsViewHolder, position: Int) {
        holder.binding?.bean=getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NewsViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_news, parent, false)
        return NewsViewHolder(view)
    }


}